define(['app', 'config','constants'], function (app, config,constants) {

    app.controller('MainCtrl', ['$scope', '$state', '$stateParams', '$$gold', '$location', '$timeout', '$modal', '$rootScope','$interval', 'growl','localStorageService',
        function ($scope, $state, $stateParams,$$gold, $location, $timeout, $modal, $rootScope,$interval, growl,localStorageService) {


            $scope.config=config;

            $scope.constants = constants;



            //首页工具显示弹出
            $scope.openIndexToll = function () {
                $("#indexToll").toggle();
                $("#toprightnone").hide();
            };

            $scope.openLogoutModal = function () {
                $modal.open({
                    templateUrl: 'dashboard/modal/loginOutModal.tpl.html',
                    backdrop:'static',
                    resolve: {
                        user: function () {
                            return $scope.user;
                        }
                    },
                    controller: function ($scope, $modalInstance, user, $state) {
                        $scope.logouting = false;

                        var doLogout = function () {

                            var options = {
                                userCode: user.userCode,
                                onSuccess: function(){
                                    $state.go('dashboard');
                                    $modalInstance.close();
                                }
                            };

                            $$gold.$user.logout(options);
                        };

                        $scope.ok = function () {
                            doLogout();
                            $scope.logouting = true;
                        };
                        $scope.cancel = function () {
                            $modalInstance.dismiss('cancel');
                        };
                    }
                })
            };


//            屏蔽系统快捷键，执行自定义快捷键
            var alreadyOpen = true;

            $scope.hideMenu = function () {
                $("#push-menu-container").removeClass('push-menu-toright');
                $("#push-menu").removeClass('push-menu-open');
            };


            var organizationListModalInstance;

            //阻止事件冒泡
            function stopBubble(e){
                // 如果传入了事件对象，那么就是非ie浏览器
                if(e&&e.stopPropagation){
                    //因此它支持W3C的stopPropagation()方法
                    e.stopPropagation();
                }else{
                    //否则我们使用ie的方法来取消事件冒泡
                    window.event.cancelBubble = true;
                }
            }
            $scope.openwin = function(url) {
                window.open (url, "newwindow", "height=1024, width=10243, top=200,left=200 toolbar =no, menubar=no, scrollbars=no, resizable=no, location=no, status=no")
                //window.showModalDialog(url,window,"dialogWidth:1024px;dialogHeight:768px;scroll:no;help:no");
                window.opener=null;
                window.open("","_self");
                //window.parent.close()
            };

            var init = function () {
                $scope.show=true;
            };
            init();
        }]);
});
